package pers.zxk.jlytnews.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


/**
 * Servlet implementation class MyServlet
 */
public class MyServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String method = req.getParameter("method");

        System.out.println(method);
        getdataToTree(req,resp);
        if(method.equals("getdataToTree"))
        {
        }
    }

    //返回数据
    private void getdataToTree(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        req.setCharacterEncoding("utf-8");
        String str="[{\"age\":15,\"fullName\":\"John Doe\"},{\"age\":20,\"fullName\":\"Janette Doe\"}]";

        //输出
        PrintWriter out = resp.getWriter() ;
        out.write(str);//注意这里向jsp输出的流，在script中的截获方法
        out.flush();
        out.close();
    }
}